package com.controller;

import com.bean.Person;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;

/**
 * @author WZ
 * @version 1.0
 * @date 2021/8/31 11:16
 */
@Controller
@Slf4j
public class HelloController {
	@Autowired
	 Person person;
	@Autowired
	JdbcTemplate jdbcTemplate;

	@Autowired
	DataSource dataSource;

	@RequestMapping("/person")
	@ResponseBody
	public Person person(){
		return person;
	}

	@RequestMapping(value = {"/","/login"})
	public String homePage(){
		return  "login";
	}

	@RequestMapping(value = "/sql")
	@ResponseBody
	public String druidSqlListener(){
		String sql="select count(*) from testtable";
		Long aLong = jdbcTemplate.queryForObject(sql, Long.class);
		log.info("记录数： {}",aLong);

		log.info("数据源类型： {}",dataSource.getClass());

		return aLong.toString();
	}
}
